package com.sync.syncmasterdata.product.service;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.sync.syncmasterdata.product.entity.BPM.InventoryLdtDeleteEntity;
import com.sync.syncmasterdata.product.entity.BPM.InventoryForItemSheetEntity;
import com.sync.syncmasterdata.product.repository.BPM.DelectLdtItemSheet;
import com.sync.syncmasterdata.product.repository.BPM.SelectLdtItemSheet;
import com.sync.syncmasterdata.product.repository.BPM.UpdateLdtItemSheetRepository;
import lombok.extern.slf4j.Slf4j;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;


@Transactional
@Service
@Slf4j
public class BPMSynchronizationService {
    @Autowired
    private SelectLdtItemSheet selectLdtItemSheet;

    @Autowired
    private UpdateLdtItemSheetRepository updateLdtItemSheetRepository;

    @Autowired
    private DelectLdtItemSheet delectLdtItemSheet;

    @Autowired
    private ObjectMapper objectMapper;

    /**
     * 根据parentId获取LDT明细表中需要新增产品信息
     * @param id
     * @return
     */
    public List<InventoryForItemSheetEntity> getProductInformation(String id){
        return selectLdtItemSheet.getProductInformation(id);
    }

    /**
     * 根据parentId获取LDT明细表中需要停用产品信息
     * @param id
     * @return
     */
    public List<InventoryLdtDeleteEntity> getDelectProduct(String id){
        return delectLdtItemSheet.getDelectProduct(id);
    }

    /**
     * 新增完成返回各系统id
     * @param CRM_id
     * @param ERP_id
     * @param id
     */
    public void getUpdateLdtItemSheet (String CRM_id,String ERP_id,String id){
        Integer result = updateLdtItemSheetRepository.getUpdateResults(CRM_id,ERP_id,id);

        if (result>0) {
            log.info("更新BPM流程明细记录成功id-{},code-{}", id, ERP_id);
        }else {
            log.info("此记录异常id-{},code-{}", id, ERP_id);
        }
    }
    /**
     * 返回产品推送结果
     * @param id
     */
    public void getUpdatePushed (String id){
        Integer result = updateLdtItemSheetRepository.getUpdatePushed(id);
        if (result>0) {
            log.info("更新BPM推送结果成功id-{}", id);
        }else {
            log.info("结果推送异常id-{}", id);
        }
    }





}
